<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="合同信息">
              <j-search-select-tag placeholder="请选择合同信息" v-model="queryParam.leaseContractId"
                                   :async="true"  dict="zcgl_lease_contract_info,contract_num,id"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="资产信息">
              <j-search-select-tag placeholder="请选择资产信息" v-model="queryParam.assetId"
                                   :async="true"    dict="zcgl_asset_info,asset_name,id"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="管理人员">
              <j-search-select-tag placeholder="请选管理人员" :async="true" v-model="queryParam.managerId"
                                   dict="sys_user,realname,id" />
            </a-form-item>
          </a-col>
          <a-col v-show="false" :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="支付状态">
              <a-input placeholder="请选择支付状态" v-model="queryParam.payStatus"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="管区">
                <j-dict-select-tag placeholder="请选管区" :async="true" v-model="queryParam.regional"
                                   dictCode="zcgl_regional" />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="客户信息">
                <j-search-select-tag placeholder="请选择客户信息" v-model="queryParam.customerId"
                                     :async="true"   dict="zcgl_customer_info,name,id"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="支付方式">
                <j-dict-select-tag placeholder="请选择支付方式" v-model="queryParam.payType" dictCode="pay_type"/>
              </a-form-item>
            </a-col>
            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <a-form-item label="开始日期">
                <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.startTime_begin"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.startTime_end"></j-date>
              </a-form-item>
            </a-col>
            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <a-form-item label="收款日期">
                <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.receiptDate_begin"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.receiptDate_end"></j-date>
              </a-form-item>
            </a-col>

            <a-col :xl="6" :lg="7" :md="8" :sm="24" v-is-group>
              <a-form-item label="入账公司">
                <j-company-select-tag placeholder="请选择入账公司" v-model="queryParam.rentCompanyId"/>
              </a-form-item>
            </a-col>

            <a-col :xl="6" :lg="7" :md="8" :sm="24" v-is-group>
              <a-form-item label="所属公司">
                <j-company-select-tag placeholder="请选择所属公司" v-model="queryParam.companyId"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!--      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
      <a-button v-has="'receivablesInfo:export'" type="primary" icon="download" @click="handleExportXls('已收款项信息')">导出</a-button>
      <!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
      <!--        <a-button type="primary" icon="import">导入</a-button>-->
      <!--      </a-upload>-->
      <!--      <a-button type="primary" icon="download" @click="handleExportXlsTemplate('已收款项信息模板')">模板下载</a-button>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item v-has="'receivablesInfo:delete'" key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <!--      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">-->
      <!--        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项-->
      <!--        <a style="margin-left: 24px" @click="onClearSelected">清空</a>-->
      <!--      </div>-->

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :scroll="{ x: 2000, y: screenHeight}"
        class="j-table-force-wrap"
        @change="handleTableChange">
        <!--        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"-->

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

<!--        <span slot="action" slot-scope="text, record">-->
<!--          <a v-has="'receivablesInfo:look'" @click="handleDetail(record)">查看</a>-->
<!--        </span>-->
        <span slot="action" slot-scope="text, record">

          <a v-has="'receivablesInfo:look'" @click="handleDetail(record)">查看</a>
            <a-divider type="vertical" />

            <a-dropdown>
              <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
              <a-menu slot="overlay">
                <a-menu-item v-has="'receivablesInfo:nullify'">
                    <a @click="nullify(record)">作废</a>
                </a-menu-item>
              </a-menu>
            </a-dropdown>
        </span>

      </a-table>
    </div>

    <receivablesInfo-modal ref="modalForm" @ok="modalFormOk"></receivablesInfo-modal>
    <receivablesOperation-modal ref="modalOperationForm" @ok="modalOperationOk"></receivablesOperation-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ReceivablesInfoModal from './modules/ReceivablesInfoModal'
  import ReceivablesOperationModal from './modules/ReceivablesOperationModal'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import JDate from '@/components/jeecg/JDate.vue'
  import { nullify } from '@/api/receivables'
  import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
  import { buildTableMethod, buildTableData} from '@/api/receivablesInfoData'
  import JCompanySelectTag from '@comp/jeecg/JCompanySelectTag'


  export default {
    name: 'ReceivablesInfoList',
    mixins: [JeecgListMixin, mixinDevice],
    components: {
      JDictSelectTag,
      JDate,
      JSearchSelectTag,
      JCompanySelectTag,
      ReceivablesOperationModal,
      ReceivablesInfoModal
    },
    data () {
      return buildTableData({
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            fixed: "left",
            customRender: (text, record, index) => `${(this.ipagination.current - 1) * this.ipagination.pageSize + index + 1}`
          },
          {
            title:'合同信息',
            align:"center",
            dataIndex: 'leaseContractId_dictText'
          },
          {
            title:'资产信息',
            align:"center",
            dataIndex: 'assetId_dictText'
          },
          {
            title: '资产明细',
            align: 'center',
            // fixed:"left",
            // width: 200,
            dataIndex: 'assetSubIds_dictText'
          },
          {
            title:'客户信息',
            align:"center",
            dataIndex: 'customerId_dictText'
          },
          {
            title:'款项说明',
            align:"center",
            dataIndex: 'paymentInstructions_dictText'
          },
          {
            title:'收款金额',
            align:"center",
            dataIndex: 'amountMoney',
            customRender: function (text) {
              if (!text) {
                text = 0
              }
              return text.toLocaleString("zh-Hans-CN",{style:"currency",currency:"CNY"});
            }
          },
          {
            title:'入账公司',
            align:"center",
            dataIndex: 'rentCompanyId_dictText',
          },
          {
            title:'支付方式',
            align:"center",
            dataIndex: 'payType_dictText'
          },
          {
            title:'款项周期',
            align:"center",
            dataIndex: 'startTime',
            width: 250,
            customRender:function (text, r, index) {
              // let startTime = !text?"":(text.length>10?text.substr(0,10):text)
              // let endTime = !r.endTime?"":(r.text.endTime>10?r.endTime.substr(0,10):r.endTime)
              return text + "至" + r.endTime
            }
          },
          {
            title:'收款日期',
            align:"center",
            dataIndex: 'receiptDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'收款人',
            align:"center",
            dataIndex: 'payeeBy_dictText'
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'isNullify_dictText'
          },
          {
            title:'收款说明',
            align:"center",
            dataIndex: 'payeeRemark'
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark'
          },
          {
            title: '附件',
            align: 'center',
            dataIndex: 'attachment',
            scopedSlots: { customRender: 'fileSlot' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:200,
            scopedSlots: { customRender: 'action' }
          }
        ],
        description: '应收款项信息管理页面',
        queryParam: {
          payStatus: 20
        }
      })
      // return {
      //
      // }
    },
    computed: {
      importExcelUrl: function () {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
      }
    },
    methods: buildTableMethod({
      //作废
      nullify(record){
        debugger
        var that=this;
        this.$confirm({
          title: '确认作废',
          content: '是否作废选中的已收款项数据?',
          onOk: function () {
            that.loading=true;
            nullify(record).then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.loadData()
              } else {
                that.$message.warning(res.message)
                that.loading=false;
              }
            }).finally(() => {
              that.confirmLoading = false
              // that.close()
            })
          }
        })
      },
      initDictConfig(){
        this.addColumns()
      },
      //自己的方法
      searchReset () {
        this.queryParam = { payStatus: 20 }
        this.loadData(1)
      }
    })
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>